package security.channel;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;

public class TCPChannel implements Channel {
	private Socket socket = null;
	protected PrintWriter tcpOut = null;
	protected BufferedReader tcpIn = null;
	
	public TCPChannel(Socket socket) throws IOException {
		this.socket = socket;
		this.tcpIn = new BufferedReader(new InputStreamReader(socket.getInputStream()));
		this.tcpOut = new PrintWriter(socket.getOutputStream(), true);
	}

	@Override
	public void println(String message) {
		//System.out.println("ueber tcp senden:" + message); //TODO delete
		this.tcpOut.println(message);
	}

	@Override
	public String readLine() throws IOException {
		String message = tcpIn.readLine();
		//System.out.println("mit tcp erhalten: " + message);
		return message;
	}
	
	@Override
	public boolean isInputShutdown() {
		return this.socket.isInputShutdown();
	}
	
	@Override
	public void close() throws IOException {
		this.socket.close();
	}
	
	@Override
	public boolean isClosed() {
		return this.socket.isClosed();
	}
	
	@Override
	public InetAddress getInetAddress() {
		return this.socket.getInetAddress();
	}
}